package com.xuecheng.manage_cms.controller;

import com.xuecheng.api.cms.CmsSiteControllerApi;
import com.xuecheng.framework.domain.cms.CmsSite;
import com.xuecheng.framework.model.response.QueryResponseResult;
import com.xuecheng.framework.model.response.ResponseResult;
import com.xuecheng.manage_cms.service.CmsSiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 站点管理
 */
@RestController
@RequestMapping("/cms/site")
public class CmsSiteController implements CmsSiteControllerApi {

    @Autowired
    private CmsSiteService cmsSiteService;
    /**
     * 新增站点
     * @param page
     * @param size
     * @param cmsSite
     * @return
     */
    @Override
    @GetMapping("/list/{page}/{size}")
    public QueryResponseResult findList(@PathVariable(name ="page") int page,@PathVariable("size") int size, CmsSite cmsSite) {
        return cmsSiteService.findList(page,size,cmsSite);
    }

    /**
     * 查询所有站点信息
     * @return
     */
    @Override
    @GetMapping("/allList")
    public ResponseResult<List<CmsSite>> findAllList(){
        return cmsSiteService.findAllList();
    }

    /**
     * 修改站点
     * @param cmsSite
     * @return
     */
    @Override
    @PostMapping("/add")
    public ResponseResult<CmsSite> add(@RequestBody CmsSite cmsSite) {
        return cmsSiteService.add(cmsSite);
    }

    /**
     * 查询单个站点
     * @param id
     * @return
     */
    @Override
    @GetMapping("/get/{id}")
    public ResponseResult<CmsSite> findById(@PathVariable("id") String id) {
        return cmsSiteService.findById(id);
    }


    @Override
    @PutMapping("/edit")
    public ResponseResult<CmsSite> edit(@RequestBody CmsSite cmsSite) {
        return cmsSiteService.update(cmsSite);
    }


    /**
     * 删除站点
     * @param id
     * @return
     */
    @Override
    @DeleteMapping("/del/{id}")
    public ResponseResult delete(@PathVariable("id") String id) {
        return cmsSiteService.delete(id);
    }
}
